<form id="msgForm" class="msgForm">
<div class="client sendmail">
	<div class="sendline cf">
		<label class="username">收件人：</label>
		<span class="intext relative">
			<span class="innerborder">
				<input type="text" autocomplete="off" name="user_name" id="msg_user_name"  class="deftest w200 h34" value="{$follow_user['user_name']}" disabled="disabled" style="background-color: rgb(250, 247, 247); ">
                <div class="handlist" id="jqury-handlist" style="height: 190px; display: none; ">
                	<ul></ul>
                </div>
			</span>
		</span>
	</div>
	<div class="sendline cf" style="padding-bottom: 12px; _padding-bottom:16px">
		<label class="usercontent">内&nbsp;容：</label>
		<span class="intext">
			<span class="innerborder">
				<textarea id="msg_message" name="message" class="PUB_TXT"></textarea>
			</span>
		</span>
	</div>
	<div id="jqeury-smsinfo" style="padding-left: 55px; margin-bottom: 8px; display: none; "></div>
	<div id="send_div" class="sendsubmit" style="_padding-left:57px; position:relative;">
    	<div id="msg_user_name_tip" style="display:none; position:absolute; top:5px; left:100px;"></div>
		<a id="msg_send_btn" class="bigbutton bigbuttongray calloff" href="javascript:void(0);">发送</a>
	</div>
</div>
</form>
<script type="text/javascript">
jQuery(function($){
	$("#fans_list .pagination a").live('click',function(){
		var page = this.getAttribute('page');
		if(page != null)
		{
			var query = new Object();
			query.page = page;
			$("#msg_fans_loading").show();
			$.ajax({
				url: SITE_PATH+"services/service.php?m=user&a=getfans",
				type: "POST",
				data:query,
				dataType: "html",
				success: function(html){
					$("#fans_list").html(html);
					$("#msg_fans_loading").hide();
				},
				error:function(){
					$("#msg_fans_loading").hide();
				}
			});
		}
	});
	
	$("#fans_list ul li").live('click',function(){
		$("#msg_user_name").attr('check',1);
		$("#msg_user_name_tip").hide();
		$("#msg_user_name").val(this.getAttribute('uname'));
	});
	
	$("#msg_message").bind("blur change",function(){
		var message = $.trim(this.value);
		var len = $.getStringLength(message);
		
		if(len < 2 || len >200)
		{
			$("#msg_message").attr('check',0);
			$("#msg_message_tip").show().html('内容由2到200个字符组成，一个汉字两个字符');
			$("#msg_send_btn").removeClass("callon").addClass("calloff");
			
		}
		else
		{
			$("#msg_message").attr('check',1);
			$("#msg_message_tip").hide();
			$("#msg_send_btn").removeClass("calloff").addClass("callon");
			
		}
	});
	
	$("#msg_user_name").bind('change',function(){
		checkMsgUser(true);
	});
	$("#msg_send_btn").click(function(){
		if($(this).hasClass("calloff"))
		{
			return;	
		}
		$("#msgForm").submit();
	});
	
	$("#msgForm").submit(function(){
		$(".msg_tip").hide();
		$(".msg_loading").hide();
		
		var user_name = $.trim(this.user_name.value);
		if(user_name == '')
		{
			$("#msg_user_name_tip").show().html('请选择或输入你要发信的收件人');
			return false;	
		}
		
		if($("#msg_user_name").attr('check') == 0)
		{
			checkMsgUser(false);
			if($("#msg_user_name").attr('check') == 0)
			{
				$("#msg_user_name_tip").show().html('只能给Fans发私信哦');
				return false;	
			}
		}
		
		var message = $.trim(this.message.value);
		var len = $.getStringLength(message);
		if(len < 2 || len >200)
		{
			$("#msg_message_tip").show().html('内容由2到200个字符组成，一个汉字两个字符');
			return false;
		}
		
		$("#msg_send_btn").attr('disabled',true);
		$("#msg_send_loading").show();
		var query = new Object;
		query.user_name = $("#msg_user_name").val();
		query.message = $("#msg_message").val();
		
		$.ajax({
			url: SITE_PATH+"services/service.php?m=user&a=sendmsg",
			type: "POST",
			data:query,
			dataType: "json",
			success: function(result){
				if(result.status > 0)
				{
					var fun = function(){
						location.href = "{u u/message uid=$_FANWE['uid']}";
					};
					setTimeout(fun,1);
				}
				else if(result.status < 0)
				{
					$("#msg_user_name_tip").show().html('只能给Fans发私信哦');
				}
				else
				{
					alert('发送信息失败，请稍候重新发送');
				}
				
				$("#msg_send_loading").hide();
				$("#msg_send_btn").attr('disabled',false);
			},
			error:function(){
				alert('发送信息失败，请稍候重新发送');
				$("#msg_send_loading").hide();
				$("#msg_send_btn").attr('disabled',false);
			}
		});
		
		return false;
	});
});

function checkMsgUser(async)
{
	var user_name = $.trim($("#msg_user_name").val());
	if(user_name != '')
	{
		$("#msg_user_name_loading").show();
		$("#msg_user_name_tip").hide();
		$("#msg_user_name").attr('check',0);
		var query = new Object();
		query.user_name = user_name;
		$.ajax({
			url: SITE_PATH+"services/service.php?m=user&a=smguser",
			type: "POST",
			data:query,
			async:async,
			dataType: "json",
			success: function(result){
				if(result.status == 1)
				{
					$("#msg_user_name").attr('check',1);
					$("#msg_user_name").val(result.user.user_name);
				}
				else
				{
					$("#msg_user_name_tip").show().html('只能给Fans发私信哦');
				}
				$("#msg_user_name_loading").hide();
			},
			error:function(){
				$("#msg_user_name_loading").hide();
			}
		});
	}
}
</script>